package com.system.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.system.entity.FoodClassify;
import com.system.service.FoodServiceImpl;
import com.system.service.IFoodService;

public class ChangeFoodClassifyServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

    public ChangeFoodClassifyServlet() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setCharacterEncoding("utf-8");
		response.setContentType("text/html");
		request.setCharacterEncoding("utf-8");
		
		String classifyNum = request.getParameter("type");
		String classifyName = request.getParameter("name");
		String classifyInfo = request.getParameter("exp");
		String oldID = request.getParameter("oldType");
		IFoodService foodService = new FoodServiceImpl();
		FoodClassify foodClassify = new FoodClassify(classifyNum, classifyName, classifyInfo);
		PrintWriter out = response.getWriter();
		if (foodService.changeFoodClassify(foodClassify,oldID) == "1" ) {
			out.print("{\"code\":\"1\"}");
		}else {
			out.print("{\"code\":\"0\"}");
		}
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
